package edu.sctu.zcy.month201506.day20150623.jsontest;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;

import java.io.IOException;

/**
 * Created by user24 on 2015/6/23.
 */
public class GetJsonData {

    JsonAppBean1 jsonAppBean1;
    public JsonAppBean1 sendGet(String url){

        HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();
        CloseableHttpClient closeableHttpClient = httpClientBuilder.build();

        HttpGet httpGet = new HttpGet(url);

        try {
            HttpResponse httpResponse = closeableHttpClient.execute(httpGet);
            HttpEntity entity = httpResponse.getEntity();

            if(entity != null){
              jsonAppBean1 = new ParseJsonData().getData(EntityUtils.toString(entity));
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

     return jsonAppBean1;
    }
}
